package models

import (
	"gorm.io/gorm"
	"house-src/basic/config"
)

// 客户
type Customer struct {
	gorm.Model
	Mobile   string `json:"mobile" gorm:"type:varchar(18);unique;comment:'手机号'"`
	Password string `json:"password" gorm:"type:varchar(32);comment:'密码'"`
	UType    int    `json:"u_type" gorm:"type:int;comment:'类型 1-管理员 2-保洁师 3-客户'"`
	Status   int    `json:"status" gorm:"type:int;comment:'状态 1-正常 2-注销'"`
}

func (c *Customer) TableName() string {
	return "customer"
}

// 添加
func (c *Customer) AddCustomer() error {
	return config.DB.Create(&c).Error
}

// 根据id查询
func (c *Customer) GetCustomerById(id int) error {
	return config.DB.Model(&Customer{}).Where("id = ?", id).Limit(1).Find(&c).Error
}

// 根据手机号查询
func (c *Customer) GetCustomerInfo(mobile string) error {
	return config.DB.Model(&Customer{}).Where("mobile = ?", mobile).Limit(1).Find(&c).Error
}
